package com.yiwei.zxp.fragment;

import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yiwei.zxp.R;
import com.yiwei.zxp.activity.ShopIdentityInfoActivity;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 18-8-2.
 */

public class ShopFirstShopFragment extends BaseFragment {

    Unbinder unbinder;
    @BindView(R.id.layout_no_take)
    LinearLayout layoutNoTake;
    @BindView(R.id.img_photo)
    ImageView imgPhoto;
    @BindView(R.id.btn_retake)
    TextView btnRetake;
    @BindView(R.id.btn_submit)
    TextView btnSubmit;
    private String imagePath;

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_shop_first_photo;
    }

    @Override
    protected void initView() {
        if(!TextUtils.isEmpty(imagePath)){
            layoutNoTake.setVisibility(View.GONE);
            btnRetake.setVisibility(View.VISIBLE);
            btnSubmit.setSelected(true);
            btnSubmit.setEnabled(true);
            Glide.with(this).load(imagePath).into(imgPhoto);
        }
    }

    public void setImageBitmap(Bitmap bitmap) {
        layoutNoTake.setVisibility(View.GONE);
        btnRetake.setVisibility(View.VISIBLE);
        btnSubmit.setEnabled(true);
        btnSubmit.setSelected(true);
        imgPhoto.setImageBitmap(bitmap);
    }

    public void setImageFile(String imagePath) {
        this.imagePath = imagePath;

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.layout_no_take, R.id.btn_retake, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.layout_no_take:
                ((ShopIdentityInfoActivity) getActivity()).goToTakePhoto();
                break;
            case R.id.btn_retake:
                ((ShopIdentityInfoActivity) getActivity()).goToTakePhoto();
                break;
            case R.id.btn_submit:
                getActivity().finish();
                break;
        }
    }
}
